﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using System.Collections;
using BLL.TcpUdp;
using System.Threading;
using Framework.Kit;
using BLL.Dataprogram;

namespace Server
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        /*****************服务器全局变量操作区域***************/
        private static ushort port=Convert.ToUInt16(Framework.Kit.AppOpr.GetConfigStrings("server_port"));
        private static ushort client_num = Convert.ToUInt16(Framework.Kit.AppOpr.GetConfigStrings("server_num"));
        public static Hashtable m_ChannelSock = new Hashtable();

        public static BLL.TcpUdp.Server svr =new BLL.TcpUdp.Server(port, client_num, new Coder());
        //当前拍卖会编号
        public static string currentAuctionNo="";
        //当前标的编号
        public static string currentTargetNo = "";

        /// <summary>
        /// 开启服务器
        /// </summary>
        public static void startServer()
        {
            try
            {
                ThreadStart myThreadDelegate = new ThreadStart(Listen);
                Thread myThread = new Thread(myThreadDelegate);
                myThread.Start();
            }
            catch(Exception ex)
            {
                other.WriteErrLog("开启服务器", ex);
            }
        }

        /// <summary>
        /// 监听函数
        /// </summary>
        public static void Listen()
        {
            try
            {
                App.svr.Start();
            }
            catch (Exception ex)
            {
                other.WriteErrLog("服务器监听操作", ex);
            }
        }

        /// <summary>
        /// 数据发送
        /// </summary>
        /// <param name="eClient">客户端对象</param>
        /// <param name="cmdType">commandType 对象</param>
        /// <param name="content">消息内容</param>
        public static void sendData(Session eClient,commandType cmdType, string content)
        {
            try
            {
                DataproAnaly da = new DataproAnaly();
                da.DataKey = "12345678";
                da.CmdType = cmdType;
                da.DataBody = content;
                App.svr.Send(eClient,da.encodeData());
            }
            catch (Exception ex)
            {
                other.WriteErrLog("服务器数据发送操作", ex);
            }
        }
    }
}
